<?php

/*
* Created on 18/05/2006
*
* @author Rafael Guerrero
*/
class WorkflowDefinitionHandler extends BaseHandler {

	// ----------------------------------------
	// Props
	// ----------------------------------------
	/**
	 * @type BaseHandler
	 */
	private $defaultHandler;
	/**
	 * @type DocTypeHandler
	 */
	private $docTypeHandler;
	/**
	 * @type NetworkHandler
	 */
	private $networkHandler;
	/**
	 * @type TransSetListHandler
	 */
	private $transSetListHandler;

	/**
	 * @type PlaceSetListHandler
	 */
	private $placeSetListHandler;

	public function __construct() {
		$this->docTypeHandler = new DocTypeHandler();
		$this->networkHandler = new NetworkHandler();
	}

	// ----------------------------------------
	// DefaultHandler Methods
	// ----------------------------------------

	public function startElement(& $parser, $tag, $attributes) {
		parent :: startElement($parser, $tag, $attributes);
		switch ($tag) {
			case 'docType':
				$this->defaultHandler = $this->docTypeHandler;
				break;
			case 'network':
				$this->defaultHandler = $this->networkHandler;
				break;
			case 'transSetList':
				$nodesByName =& $this->networkHandler -> getNodesByName();
				$fieldByName =& $this->docTypeHandler -> getFieldByName();
				
				$this->transSetListHandler = new TransSetListHandler($nodesByName, $fieldByName);
				$this->defaultHandler = $this->transSetListHandler;
				break;
			case 'placeSetList':
				$nodesByName =& $this->networkHandler -> getNodesByName();
				$fieldByName =& $this->docTypeHandler -> getFieldByName();
				$variantByName =& $this->docTypeHandler -> getVariantByName();
				$this->placeSetListHandler = new PlaceSetListHandler($nodesByName, $fieldByName,$variantByName);
				$this->defaultHandler = $this->placeSetListHandler;
				break;
		}

		if ($this->defaultHandler != NULL) {
			$this->defaultHandler -> startElement($parser, $tag, $attributes);
		}
	}

	public function endElement(& $parser, $tag) {
		if ($this->defaultHandler != NULL) {
			$this->defaultHandler -> endElement($parser, $tag);
		}
	}

	public function characters(& $parser, $data) {
		if ($this->defaultHandler != NULL) {
			$this->defaultHandler -> characters($parser, $data);
		}
	}

	// ----------------------------------------
	// Props Methods
	// ----------------------------------------
/**
 * @return DocTypeHandler
 */
	public function & getDocTypeHandler() {
		return $this->docTypeHandler;
	}
/**
 * @return NetworkHandler
 */
	public function & getNetworkHandler() {
		return $this->networkHandler;
	}
/**
 * @return TransSetListHandler
 */
	public function & getTransSetListHandler() {
		return $this->transSetListHandler;
	}
/**
 * @return PlaceSetListHandler
 */
	public function & getPlaceSetListHandler() {
		return $this->placeSetListHandler;
	}
}
?>
